package thread.demo07.ExecutorService;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 自定义ThreadFactory、自定义线程拒绝策略
 * 
 * @author mengzhang6
 *
 */
public class ThreadPoolDemo4 {
	public static void main(String[] args) {

		ExecutorService executorService = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS,
				new LinkedBlockingQueue<>(10), new ThreadFactory() { // 自定义ThreadFactory
					@Override
					public Thread newThread(Runnable r) {
						Thread thread = new Thread(r);
						thread.setName(r.getClass().getName());
						return thread;
					}
				}, new ThreadPoolExecutor.AbortPolicy()); // 自定义线程拒绝策略

		for (int i = 0; i < 10; i++) {
			int index = i;
			executorService.submit(() -> System.out.println("i:" + index));
		}

		executorService.shutdown();
	}
}
